package vfrpt

class PartProgressController {

    def dynamicQueryService
    def partProgress(){
        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent
        def tableHeadList=[]
        def partProgress=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        //产品方向的查询条件
        params.SYS_QUERY_NAME = 'partDirectionList'
        def partDirectionList = dynamicQueryService.queryForList(params)
        //合计
        def partProgressSumQty=[]
        if(params.EXPORT_CONTENT_NAME=='Excel'){
            params.SYS_QUERY_NAME = 'partProgress'
            partProgress = dynamicQueryService.queryForList(params)
            if (partProgress.size() > 0) {
                tableHeadList = partProgress[0].keySet()
            }
            println(params.step)
            println(params.part)
            params.SYS_QUERY_NAME = 'partProgressCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT

            println(totalCount)

            params.SYS_QUERY_NAME = 'partProgressSumQty'
            partProgressSumQty = dynamicQueryService.queryForList(params)

        }
        [startno:params.startno?:'',endno:params.endno?:'',pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent,
         tableHeadList:tableHeadList,partProgress:partProgress,
         startTime:params.startTime,endTime:params.endTime,partName:params.partName,stepName:params.stepName,
         endDocId:params.endDocId,startDocId:params.startDocId,partDesc:params.partDesc,lotId:params.lotId,part:params.part?:'',step:params.step?:'',
         spec1:params.spec1,ZT:params.ZT,partProgressSumQty:partProgressSumQty,
         partDirection:params.partDirection?:'',partDirectionList:partDirectionList
        ]

    }

    def partProgressStep(){

        def pageCurrent = params.pageCurrent ? Integer.parseInt(params.pageCurrent) : 1
        def pageSize = params.pageSize ? Integer.parseInt(params.pageSize) : 10
        params.startno = (pageSize * (pageCurrent - 1)) + 1
        params.endno = pageSize * pageCurrent

        println(params.docId)
        println(params.recpId)
        println(params.state)
        def tableHeadList=[]
        def partProgressStep=[]
        def pageSizeList = [10,20,50,100]
        def totalCount =0
        //合计
        def partProgressStepSumQty=[]
            params.SYS_QUERY_NAME = 'partProgressStep'
            partProgressStep = dynamicQueryService.queryForList(params)
            if (partProgressStep.size() > 0) {
                tableHeadList = partProgressStep[0].keySet()
            }
            params.SYS_QUERY_NAME = 'partProgressStepCount'
            totalCount = dynamicQueryService.queryForList(params)[0].TOTALCOUNT


            params.SYS_QUERY_NAME = 'partProgressStepSumQty'
            partProgressStepSumQty = dynamicQueryService.queryForList(params)

        println(partProgressStep)

        [startno:params.startno?:'',endno:params.endno?:'',pageSize     : pageSize, totalCount: totalCount, pageSizeList: pageSizeList,pageCurrent:pageCurrent,
         tableHeadList:tableHeadList,partProgressStep:partProgressStep,
         startTime:params.startTime,endTime:params.endTime,docId:params.docId?:'',recpId:params.recpId?:'',
         state:params.state?:'',partProgressStepSumQty:partProgressStepSumQty,
       ]
    }
    //一阶导出
    def exportExcel() {
        def sysQueryName


        sysQueryName = params.SYS_QUERY_NAME

        params.startno = 1
        params.endno = 99999999999999999



        params.SYS_QUERY_NAME = sysQueryName

        def dataList = dynamicQueryService.queryForList(params)

        def tableHeadList =  []
        if(sysQueryName=='partFinList'){
            dataList=TranposUtils.colToRow('STEP_DESC','STEP_QTY',dataList)
            println(dataList)
        }
        if(dataList.size()>0){
            tableHeadList =  dataList[0].keySet()
        }
        String filename = new String("${sysQueryName}.xls".getBytes("UTF-8"), "UTF-8");
        response.setContentType('application/vnd.ms-excel;charset=UTF-8')
        response.setHeader('Content-disposition', "attachment;filename=${filename};charset=UTF-8")
        response.setCharacterEncoding("UTF-8");
        render(template: "export${params.EXPORT_CONTENT_NAME}", model: [dataList: dataList,tableHeadList:tableHeadList,startno:params.startno?:'',endno:params.endno?:''])
    }

}
